<template>
  <div>
    登录表单内容
    <div>
      <input type="text" v-model="user.username">
      <input type="text" v-model="user.password">
    </div>
    <button @click="submit">登录</button>
  </div>
</template>

<script>
import axios from 'Axios'
export default{
  data() {
    return {
      user: {
        username: 'admin',
        password: '39c5841c3c6b8f795febbf143628ad94'
      },
    }
  },
  methods: {
    submit() {
      console.log('user', this.user)
      this.$request({
        url: '/admin/index/login',
        data: this.user,
        method: 'post',
      }).then(({ data: res }) => {
        console.log('res', res)
        const { data: user, status, msg } = res
        if (!status) {
          alert(msg)
          this.user = {}
          return
        }
        console.log('user', user)
        const user_json = JSON.stringify(user)
        localStorage.setItem('user', user_json)
        this.$router.push('/home')
      })
    },
  }
}
</script>

<style>
</style>
